package it.trekker.dialogs;

import it.trekker.R;
import it.trekker.step.StepDetector;
import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class SetAlphaDialog extends Dialog {
	
	// GUI Components
	private EditText alphaValue_et = null;
	private Button okBt = null;
	private Button cancelBt = null;
	
	private Context context = null;
	private StepDetector stepDetector = null;
	
	public SetAlphaDialog(Context context, StepDetector stepDetector) {
		
		super(context);
		
		this.context = context;
		this.stepDetector = stepDetector;

		setContentView(R.layout.set_alpha_dialog);
		setTitle("Set alpha");

		alphaValue_et = (EditText) findViewById(R.id.alpha_value);
		alphaValue_et.setText(String.valueOf(stepDetector.getAlpha()));
		
		Button okBt = (Button) findViewById(R.id.ok_bt);
		okBt.setOnClickListener(new OkButtonListener());
		
		Button cancelBt = (Button) findViewById(R.id.cancel_bt);
		cancelBt.setOnClickListener(new CancelButtonListener());
		
	}
	
	public double getAlphaValue() {
		return Double.valueOf(alphaValue_et.getText().toString());
	}

	public void setAlphaValue(double alpha_value) {
		this.alphaValue_et.setText(String.valueOf(alpha_value));
	}
	
	public void setOkButtonListener(View.OnClickListener listener) {
		okBt.setOnClickListener(listener);
	}
	
	public void setCancelButtonListener(View.OnClickListener listener) {
		cancelBt.setOnClickListener(listener);
	}
	
	
	
	//************************************************************//
  	//********************* Listener classes *********************//
  	//************************************************************//
	
	private class OkButtonListener implements View.OnClickListener {

		@Override
		public void onClick(View v) {
			stepDetector.setAlpha(getAlphaValue());
			dismiss();
			Toast.makeText(context, "Alpha value setted to " + stepDetector.getAlpha(), Toast.LENGTH_LONG).show();
		}
		
	} 
	
	private class CancelButtonListener implements View.OnClickListener {

		@Override
		public void onClick(View v) {
			dismiss();
		}
		
	} 
}
